<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p class="p"></p>
</body>
<script>
    let person = {name:'张飞',age:17,hobbie:['烫头','抽烟']}

    // Vue3的响应式原理
    // let p = new Proxy(person,{
    //     get(target,prop){
    //         console.log('get被调用了');
    //         return Reflect.get(target,prop);
    //     },
    //     set(target,prop,val){
    //         console.log('set被调用了');
    //         return Reflect.set(target,prop,val);
    //     },
    //     deleteProperty(target,prop){
    //         console.log('deleteProperty被调用了');
    //         return Reflect.deleteProperty(target,prop);
    //     }
    // })
    
    // Vue2的响应式原理
    let p = {}
    Object.defineProperty(p,"name",{
        get(){
            return person.name
        },
        set(val){
            person.name = val
        }
    })
    Object.defineProperty(p,"hobbie",{
        get(){
            return person.hobbie
        },
        set(val){
            person.hobbie = val
        }
    })
    Object.defineProperty(p,"age",{
        get(){
            console.log('get被调用了');
            return person.age
        },
        set(val){
            console.log('set被调用了');
            person.age = val
        }
    })

    // let target={ name: 'curry', age: 30 };
    // let source={ sex: 'man', job: 'player' }
    // let result=Object.assign(target,source);
    // console.log(target);
    // let arr1 = [1,2,3,6,5];
    // let arr2 = [4,5,6,1,2]
    // for(let k in arr2){
    //     arr1.push(arr2[k])
    //     for(var i=0; i<arr1.length; i++){
    //     for(var j=i+1; j<arr1.length; j++){
    //         if(arr1[i]==arr1[j]){
    //         arr1.splice(j,1);
    //         j--;
    //        }
    //      }
    //    }
    //  }
    // console.log(arr1);
    
    function timer(){
    var d=new Date();
    var n=d.toLocaleDateString();
    let t = d.toLocaleTimeString();
    return {n,t}
    }
    let times = ''
    let tms = setInterval(()=>{
        times = timer();
        let ps = document.querySelector('.p')
        ps.innerText = times.n + ' ' + times.t;
    })
</script>
</html>